package com.google.code.toub.waves.servlet;

import java.util.logging.Logger;

import com.google.code.toub.waves.editor.util.BlipEditor;
import com.google.wave.api.AbstractRobot;
import com.google.wave.api.Blip;
import com.google.wave.api.Gadget;
import com.google.wave.api.event.GadgetStateChangedEvent;
import com.google.wave.api.event.WaveletBlipCreatedEvent;
import com.google.wave.api.event.WaveletSelfAddedEvent;

@SuppressWarnings("serial")
public class WaveExtensionServlet extends AbstractRobot {

	private static final String VOTE_GADGET_URL = "http://toub-waves.googlecode.com/svn/trunk/toub-waves-vote-gadget/gadget.xml";

	private final BlipEditor blipEditor = new BlipEditor();

	/**
	 * Logger
	 */
	private final Logger logger = Logger.getLogger(getClass().getName());

	@Override
	protected String getRobotName() {
		return "Wave++";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.wave.api.AbstractRobot#onGadgetStateChanged(com.google.wave
	 * .api.event.GadgetStateChangedEvent)
	 */
	@Override
	public void onGadgetStateChanged(GadgetStateChangedEvent event) {
		Blip blip = event.getBlip();
		Gadget gadget = (Gadget) blip.getElements().get(event.getIndex());
		String count = gadget.getProperty("count");

		blip.append("State changed changed " + count);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.wave.api.AbstractRobot#onWaveletBlipCreated(com.google.wave
	 * .api.event.WaveletBlipCreatedEvent)
	 */
	@Override
	public void onWaveletBlipCreated(WaveletBlipCreatedEvent event) {
		super.onWaveletBlipCreated(event);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.wave.api.AbstractRobot#onWaveletSelfAdded(com.google.wave.
	 * api.event.WaveletSelfAddedEvent)
	 */
	@Override
	public void onWaveletSelfAdded(WaveletSelfAddedEvent event) {
		Blip blip = event.getWavelet().reply("\nHi everybody!");
		Gadget gadget = new Gadget(VOTE_GADGET_URL);
		blip.append(gadget);
	}

}
